package com.zuxia.filter;

import com.zuxia.utils.JwtUtils;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Component
public class MyCustomInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String requestURI = request.getRequestURI();
        System.out.println("----------->"+requestURI);

        String token = request.getHeader("Authorization");
        if(token != null && !token.isEmpty()) {
            JwtUtils.jwtInfo=JwtUtils.getMemberIdByJwtToken(token);
            JwtUtils.id=JwtUtils.jwtInfo.getId();
        }
        return true;
    }
}
